function [ varargout ] = switch_tl_dlg( varargin )
%SWITCH_TL_DLG Summary of this function goes here
%
%   SWITCH_TL_DLG(varagin) Detailed explanation goes here
%
%   Inputs:
%
%
%   Outputs:
%
%
%   Syntax:
%
%
%   Example:
%
%
%   See also:
%
% 
%   Author(s): Xiaobiao Huang
%   Copyright 2013-2020 The Xiaobiao Studio.
%   $Revision: 1.0.0.0 $  $Date: 08-Jul-2013 12:49:31 $

tl_open_blockdgl_path = which('tl_open_blockdlg');
pos = strfind(tl_open_blockdgl_path,'\');

xstudioPath = [tl_open_blockdgl_path(1:pos(end-1)) 'xstudio'];

addpath(xstudioPath,'-first');

fid = fopen(tl_open_blockdgl_path);
try
	line = fgetl(fid);
	str = cell(0);
	count = 1;
	while ischar(line)
		str{count} = [line,'\n'];
		line = fgetl(fid);
		count = count+1;
	end
	fclose(fid);
catch err
		fclose(fid);
		rethrow(err);
end

str = [str{:}];
str = strrep(str,'%','%%');
fprintf('*************************************************************************\n');
if strfind(str,'tldlg(hBlock)')
	if strfind(str,'tldlg')
		str = strrep(str,'tldlg','dstabdlg');	
		fprintf('You have just switched to %s calibration tool.\n','targetLink');		
	else
		str = strrep(str,'dstabdlg','tldlg');
		fprintf('You have just switched to %s calibration tool.\n','XStudio');	
	end
else
	fprintf('You have just install %s calibration tool.\n','XStudio');
	fprintf('\tYou can use tl_switch_dlg \n\tto change calibration tool between targetLink and XStudio\n');
	str = strrep(str,'dstabdlg','tldlg');
end
fprintf('*************************************************************************\n');
newfid = fopen(tl_open_blockdgl_path,'w');
try
	fprintf(newfid,str);
	if newfid > 2
		fclose(newfid);
	end
catch err
	if newfid > 2
		fclose(newfid);
	end
	rethrow(err);
end
% open(tl_open_blockdgl_path)
end %end of function
